package com.wqi.chapter6;

public class CADSystem extends Shape{

	private Circle c;
	private Triangle t;
	private Line[] lines = new Line[10]; 
	CADSystem(int i) {
		super(i+1);
		for( int j =0;j<10;j++){
			lines[j] = new Line(j,j*j);
		}
		c = new Circle(1);
		t = new Triangle(1);
		System.out.println("Combined Constructor");
	}
	
	void cleanUp(){
		System.out.println("CADSystem.cleanUp()");
		t.cleanUp();
		c.cleanUp();
		for(int i =0;i<lines.length;i++){
			lines[i].cleanUp();
		}
		super.cleanUp();
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		CADSystem x = new CADSystem(47);
		try{
			
		}finally{
			x.cleanUp();
		}
	}

}

class Shape{
	Shape(int i){
		System.out.println("Shape constructor");
	}
	
	void cleanUp(){
		System.out.println("Shape cleanUp");
	}
}

class Circle extends Shape{

	Circle(int i) {
		super(i);
		System.out.println("Drawing a Circle");
	}
	void cleanUp(){
		System.out.println("Erasing a Circle");
		super.cleanUp();
	}
}

class Triangle extends Shape{

	Triangle(int i) {
		super(i);
		System.out.println("Drawing a Triangle");
	}
	void cleanUp(){
		System.out.println("Erasing a Triangle");
		super.cleanUp();
	}
}

class Line extends Shape{
	private int start,end;
	Line(int start,int end) {
		super(start);
		this.start = start;
		this.end = end;
		System.out.println("Drawing a line:"+
				start +" , " +end);
	}
	void cleanUp(){
		System.out.println("Erasing a Line:" + 
				start +" , "+ end);
		super.cleanUp();
	}
}
